package cn.wolfcode.luowowo.member.service.impl;

import cn.wolfcode.luowowo.member.domain.PersonInfo;
import cn.wolfcode.luowowo.member.mapper.PersonInfoMapper;
import cn.wolfcode.luowowo.member.service.IPersonInfoService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;


@Service
public class PersonInfoServiceImpl implements IPersonInfoService {

    @Autowired
    private PersonInfoMapper personInfoMapper;

    @Override
    public PersonInfo getByUserId(Long id) {
        return personInfoMapper.selectByUserId(id);
    }

    @Override
    public boolean getAttentionById(Long userId, Long id) {
        PersonInfo personInfo = personInfoMapper.selectByUserId(userId);
        if (personInfo.getAttentionUserIds().contains(id)){
            //存在说明是关注
            return true;
        }
        return false;
    }

    @Override
    public void updateAttentionByid(Long userId, Long id, boolean isatt) {
        PersonInfo personInfo = personInfoMapper.selectByUserId(userId);
        List<Long> a = personInfo.getAttentionUserIds();
        ArrayList ids = new ArrayList(a);
        if(ids != null){
            if (isatt){
                ids.remove(id);
            }else{
                ids.add(id);
            }
        }
        personInfo.setAttentionUserIds(ids);
        personInfoMapper.updateAttentionByid(personInfo);
//        if(isatt){
//            //Ids.remove(id);
////            for (int i = 0; i < Ids.size(); i++) {
//////                if(Ids.get(i) == id){
//////                    Ids.remove(i);
//////                }
//////            }
//        }else{
//            Ids.add(id);
//        }
//        personInfo.setAttentionUserIds(Ids);
//        personInfoMapper.updateAttentionByid(personInfo);
    }


}
